package org.Panel;

import org.implement.Panel.PanelSize;
import org.implement.Panel.PanelSkip;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class PlayPanel extends FaPanel {

    //界面大小属性
    int Width = 0;
    int Height = 0;
    //登陆按钮
    JButton loginButton = new JButton("登陆");
    //注册
    JButton registerButton = new JButton("注册");
    //母控件大小接口
    PanelSize panelSize;
    //母控件界面跳转接口
    PanelSkip panelSkip;

    public PlayPanel(PanelSize panelSize1, PanelSkip panelSkip1) {
        //实现接口
        panelSize = panelSize1;
        panelSkip = panelSkip1;

        //启动界面的界面id
        PanelIndex = 0;
        //属性设置
        setLayout(null);
        setSize(panelSize.getWidth(), panelSize.getHeight());
        setLocation(0,0);

        //登陆按钮设置
        loginButton.setBounds(300,150,600,150);
        loginButton.addMouseListener(new MouseAdapter() {
            //用于判定鼠标是否在按钮内
            int f=1;
            @Override
            public void mouseClicked(MouseEvent e) {}

            @Override
            public void mousePressed(MouseEvent e) {}

            @Override
            public void mouseReleased(MouseEvent e) {
                if(f==1) {
                    //跳转到登陆界面
                    panelSkip.skip(1);
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                f=1;
            }

            @Override
            public void mouseExited(MouseEvent e) {
                f=0;
            }
        });
        add(loginButton);

        //注册按钮设置
        registerButton.setBounds(300,400,600,150);
        registerButton.addMouseListener(new MouseAdapter() {
            int f=1;
            @Override
            public void mousePressed(MouseEvent e) {}

            @Override
            public void mouseReleased(MouseEvent e) {
                if(f==1) {
                    //跳转到登陆界面
                    panelSkip.skip(2);
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                f=1;
            }

            @Override
            public void mouseExited(MouseEvent e) {
                f=0;
            }
        });
        add(registerButton);

        //repaint();  //重绘

    }

    public void Run() {
        //让界面随着窗口大小变化而变化
        setSize(panelSize.getWidth(), panelSize.getHeight());
        Width = getWidth();
        Height = getHeight();
//        System.out.println(Width);
//        System.out.println(Height);

        //控件大小位置更新
        //登陆按钮
        loginButton.setBounds(300*Width/1200,150*Height/800,600*Width/1200,150*Height/800);
        //注册按钮
        registerButton.setBounds(300*Width/1200,400*Height/800,600*Width/1200,150*Height/800);

    }
}
